package basic.thread.again;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * @author bingo
 * @create 2018-02-28 15:52
 **/
public class MyLock1 implements Lock {


    @Override
    public void lock() {

    }

    @Override
    public void lockInterruptibly() throws InterruptedException {

    }

    @Override
    public boolean tryLock() {
        return false;
    }

    @Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
        return false;
    }

    @Override
    public void unlock() {

    }

    @Override
    public Condition newCondition() {
        return null;
    }

    public static void main(String[] args) {
        InnerSquence squence3 = new InnerSquence();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread()+" "+squence3.getValue());
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread()+" "+squence3.getValue());
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread()+" "+squence3.getValue());
                }
            }
        }).start();

    }

}

class  InnerSquence{

    private int value = 0;

    Lock lock = new MyLock1();

    public int getValue(){
        lock.lock();
        int i=(value++);
        System.out.print("a");
        b();
        lock.unlock();
        return  i;
    }

    public void b(){
        lock.lock();
        System.out.println(",b");
        lock.unlock();
    }

}